# -*- coding: utf-8 -*- 
# @Time : ${2020} 10:35 
# @Author : 康玉浩
# @File : 词云生成器.py
from wordcloud import WordCloud
fp = open(r"情话", encoding='UTF-8')
text = fp.read()
wordcloud=WordCloud(font_path="C:/Windows/Fonts/simfang.ttf", background_color="black",width=600,height=300,max_words=50).generate(text)
image=wordcloud.to_image()
image.save("ciyun.png")
#wordcloud支持掩码，可以利用前面处理好的图片，生成指定形状的词云：
import numpy as np
from PIL import Image
mask_pic=np.array(Image.open(r"../hx01.jpg"))
wordcloud = WordCloud(font_path=r"C:\Windows\Fonts\simfang.ttf",mask=mask_pic).generate(text)
image=wordcloud.to_image()
image.save("hx02.png")


